package com.viking.controller;

import com.viking.feign.ProductFeignService;
import com.viking.feign.StockFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private StockFeignService stockFeignService;

    @Autowired
    private ProductFeignService productFeignService;

    @RequestMapping("/add/{id}")
    public String add(@PathVariable Integer id){
        System.out.println("下单成功！");
//        String result = restTemplate.getForObject("http://stock-service:8021/stock/reduce", String.class);
        String result = stockFeignService.reduce();

        String productResult = productFeignService.get(id);
        return "ok,下单成功！库存服务调用返回："+result+",商品服务返回："+productResult;
    }
}
